package com.jince.datacenter.taskscheduler;

import java.io.File;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jince.datacenter.Constants;
import com.jince.datacenter.config.FTPConfig;
import com.jince.datacenter.service.DataImportService;
import com.jince.datacenter.utils.DateUtil;
import com.jince.datacenter.utils.FTPUtil;

@Service
public class ScheduledTaskService {

	private final static Logger logger = Logger
			.getLogger(ScheduledTaskService.class);

	@Autowired
	private FTPConfig ftpConfig;

	@Autowired
	private DataImportService dataImportService;

	// @Scheduled(fixedRate = 10000)
	public void downloadData() {
		logger.info("downloadData start");
		// 获取当日日期
		String nowDate = DateUtil.getDateToStr(DateUtil.yyyyMMdd, new Date());
		String path = Constants.ZBS + File.separator + nowDate;
		FTPUtil.bathDownload(FTPUtil.getFTPClient(ftpConfig.getIp(),
				ftpConfig.getUsername(), ftpConfig.getPassword()), path, path);

		logger.info("downloadData end");
	}

	// @Scheduled(fixedRate = 20000)
	public void importData() {
		logger.info("importData start");
		// 获取当日日期
		String nowDate = DateUtil.getDateToStr(DateUtil.yyyyMMdd, new Date());
		String path = Constants.ZBS + File.separator + nowDate;
		dataImportService.importData(path);

		logger.info("importData end");
	}

}
